const initState = {
  mainPanes: [],
  mainPanesKey: ''
}

export default {
  namespaced: true,
  state: {
    ...initState,
    initState () {
      return initState
    }
  },
  actions: {},
  mutations: {
    setMainPanes (state, info) {
      if (!info) {
        state.mainPanes = []
        state.mainPanesKey = ''
        return
      }
      // if (!state.mainPanes.length) {
      //   state.mainPanes = [...state.mainPanes, info]
      //   state.mainPanesKey = info.key
      //   return
      // }
      const keys = state.mainPanes.map(pane => pane.key)
      if (keys.includes(info.key)) {
        return
      }
      state.mainPanes = [...state.mainPanes, info]
      state.mainPanesKey = info.key
    },
    removeMainPanes (state, info) {
      state.mainPanes = state.mainPanes.filter(pane => pane.key !== info)
      state.mainPanesKey = state.mainPanes[state.mainPanes.length - 1].key
    },
    setMainPanesKey (state, info) {
      state.mainPanesKey = info
    }
  }
}
